<template>
    <view class="page">
		<block v-if="!boxHide">
			
			<view class="library_list">
				<block v-for="(item,index) in list">
					<view class="accessories_item" :key="index">
						<view class="accessories_item_content">
							<view class="accessories_item_name">名称：{{item.product_name}}</view>
							<view class="accessories_item_num">
								<text>数量：{{item.num}}</text>
 							</view>
                            <view class="accessories_item_num">
								<text>仓库：{{item.ware_name}}</text>
 							</view>
							<view class="accessories_item_time">{{item.create_at}}</view>
						</view>
                        <view class="accessories_item_confirm">
                            <view v-if="item.audit_status == 0" class="unsure">待确认</view>
                            <view v-if="item.audit_status == 1" class="sure">已确认</view>
                        </view>
						<view class="accessories_item_btn">
							<view @tap="toHandBack(item,1)">配件退还</view>
							<view @tap="toHandBack(item,2)">损件退还</view>
						</view>
					</view>
				</block>
			</view>
			
			<!-- <view class="library_prompt">共5件，还有3件未核销</view> -->
		</block>
		<Loading ref="load"></Loading>
	</view>
</template>

<script>
    export default {
        data(){
                return{
                    boxHide:true,
                    list:[],
                    loading:true,
                    page:1,
                    productId:0 
                }
            },
            onLoad(options) { 
                 this.productId = options.productId;

                this.getData(1)
            },
            onShow() {
                 if (this.$app.globalData.upData.getMyAccessoriesReceiveList) {
                    //this.list = [];
                   //this.getData(1);
                } else {
                    this.boxHide = false
                }
		    },
            onUnload() {
                console.log("是否进入----》》》》》》");
                this.$app.globalData.upData.getMyAccessoriesReceiveList = true;
            },
            onReachBottom() {
                if(this.loading){
                    this.getData(3);
                }
            },
            methods:{
                getData(type){
                    this.$refs.load.initLoading({loadType:type}).then(res =>{
                        this.boxHide = false;
                        if(type == 1 || type == 2){this.list = [];this.page = 1;this.loading = true;this.$app.globalData.upData.accessoriesLibrary = true}
                        
                        this.$api.getMyAccessoriesReceiveList({page:this.page,user_id:uni.getStorageSync("userId"),product_id:this.productId}).then(res => {
                            this.$app.globalData.upData.getMyAccessoriesReceiveList = false;
                            this.$refs.load.getLoadingData({oldData:this.list,newData:res.data}).then(res => {
                                this.list = res.list;
                                this.loading = res.loading;
                                this.page ++;
                            });
                        })
                    })
                },
                info(item){//查看详情
                    if(item.status == 1){
                        uni.navigateTo({
                            url:"/pages/accessories/pay/pay?id=" + item.product_id
                        })
                    }else{
                        uni.navigateTo({
                            url:"/pages/accessories/info/info?id=" + item.product_id
                        })
                    }
                    
                },
                toHandBack(item,type){ 
                    this.$app.globalData.upData.getMyAccessoriesReceiveList = true;
                    uni.navigateTo({
                        url:"/pages/accessories/handBank/handBank?productId="+item.product_id+"&type="+type+"&warehouseId="+item.warehouse_id+"&id="+item.id+"&num="+item.num+"&wareName="+item.ware_name
                    })
                }
            }
    }
</script>
<style>
	.page {
		padding-bottom: 80rpx;
	}
	.total_view {
		position: fixed;
		bottom: 0;
		height: 80rpx;
		display: flex;
		justify-content: space-around;
		align-items: center;
		width: 100%;
		background: #049BFF;
		z-index: 9;
		color: #fff;

	}
	.library_list{margin-top: 10upx;}
	.accessories_item{width: 690upx;margin: 30upx 0 0 30upx;padding: 30upx;box-sizing: border-box;background: #FFFFFF;font-size: 30upx;color: #333333;display: flex;flex-direction: row;align-items: center;}
	.accessories_item_content{flex-grow: 1;}
	.accessories_item_num{margin-top: 10upx;font-size: 24upx;color: #666666;}
	.accessories_item_num text:nth-child(2){margin-left: 20upx;}
	.accessories_item_time{font-size: 24upx;color: #999999;margin-top: 10upx;}
    .accessories_item_confirm{
        padding: 0rpx 15rpx;
    }

    .accessories_item_confirm .sure{
        padding:10rpx;text-align: center;background: #A5DE37;color:white;border: 2rpx solid #A5DE37;border-radius: 10rpx;font-size: 25rpx;
    }

    .accessories_item_confirm .unsure{
         padding:10rpx;text-align: center;background: #FF4351;color:white;border: 2rpx solid #FF4351;border-radius: 10rpx;font-size: 25rpx;
    }

	.accessories_item_btn{
		/* flex-grow: 1; */
	}
	.accessories_item_btn view{
		padding: 10rpx;
		text-align: center;
		background: white;
		border: 2rpx solid #EEEEEE;
		border-radius: 10rpx;
		font-size: 25rpx;
	}
	.accessories_item_btn view:nth-child(1){
		margin-bottom: 10rpx;
	}
	.accessories_item_btn view:nth-child(2){
		 background-color: #049BFF;
		 color:white;
	}
	.library_prompt{width: 100%;text-align: center;font-size: 30upx;line-height: 100upx;color: #007AFF;}
</style>